# 切片：切片(slice)是对序列型对象(如list, string, tuple)的一种高级索引方法

def list_slice_demo():
    _list = [1, 2, 3, 4, 5, 6, 7]
    print("_list", _list)
    # [1, 2, 3]
    print('_list[:3]', _list[:3])
    # [4, 5, 6, 7]
    print('_list[3:]', _list[3:])
    # [2, 3]
    print('_list[1:3]', _list[1:3])


def str_slice_demo():
    _str = 'ABCDEFG'
    print('_str', _str)
    # _str[:3] ABC
    print('_str[:3]', _str[:3])
    # _str[3:] DEFG
    print('_str[3:]', _str[3:])
    # _str[1:3] BC
    print('_str[1:3]', _str[1:3])


def dir_slice_demo():
    _dir = {'张三': 23, '李四': 24, '王五': 25, '赵六': 26}
    print('_dir', _dir)
    print('_dir[2:]', _dir[2:])


if __name__ == '__main__':
    # str_slice_demo()
    # dir_slice_demo()
    list_slice_demo()




